package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCLocationData.TemAddition;

public class TemAlarmDto {
    private int channelId;
    private boolean temAlarm;
    private int temperature;

    public int getChannelId() {
        return channelId;
    }
    public void setChannelId(int channelId) {
        this.channelId = channelId;
    }
    public boolean isTemAlarm() {
        return temAlarm;
    }
    public void setTemAlarm(boolean temAlarm) {
        this.temAlarm = temAlarm;
    }
    public int getTemperature() {
        return temperature;
    }
    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    /**
     * 解析成String拼接字符串
     * @param addition
     * @return
     */
    public static String parseString(TemAddition addition){
        return EntityConvert.convert(addition.getChannelId(), addition.getTemAlarm(), addition.getTemperature());
    }

    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static TemAddition parsePB(String str){
        TemAddition.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=3){
                builder = TemAddition.newBuilder();
                builder.setChannelId(Integer.valueOf(revert[0]));
                builder.setTemAlarm(Boolean.valueOf(revert[1]));
                builder.setTemperature(Integer.valueOf(revert[2]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }
}
